package org.ls.petclinic.web;

import org.ls.petclinic.pojo.Customer;
import org.ls.petclinic.service.CustomerService;
import org.ls.petclinic.service.impl.CustomerSericeImpl;
import org.ls.petclinic.untils.JdbcUtils;
import org.ls.petclinic.untils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description
 * @Author 浪矢先生
 * @Create 2022-06-10 0:00
 */
@WebServlet(urlPatterns = "/addCustomer")
public class AddCustomer extends BaseServlet{
    private CustomerService customerService=new CustomerSericeImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Customer customer = WebUtils.copyParamToBean(req.getParameterMap(), new Customer());
        customerService.saveCustomer(customer);
        JdbcUtils.commitAndClose();
        resp.sendRedirect(req.getContextPath() + "/jsp/getCustomer.jsp");
    }
}
